package com.jesper.seckill.service.impl;

import cn.hutool.core.util.StrUtil;
import com.jesper.seckill.entity.po.Order;
import com.jesper.seckill.mapper.OrderMapper;
import com.jesper.seckill.service.IOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sjw
 * @since 2024-01-18
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public boolean isRepeatUserGoodsSecKill(String userId, String goodsId) {
        if (StrUtil.isBlank(userId) || StrUtil.isBlank(goodsId)){
            return false;
        }
        return lambdaQuery().eq(Order::getUserId,userId)
                .eq(Order::getGoodsId,goodsId)
                .count() > 1;
    }

    @Override
    public void batchInsertOrder(List<Order> orderList) {
        this.saveBatch(orderList);
    }
}
